<?php

namespace App\Observers;

use App\Models\Product;
use App\Services\Pinyin\PinyinService;
use DB;

class ProductObserver
{
    public function created(Product $product)
    {
        $abbrname = PinyinService::make($product->name);
        DB::table('products')->where('id', $product->id)->update(['abbr' => $abbrname]);
    }


    public function updated(Product $product)
    {
        $abbrname = PinyinService::make($product->name);
        DB::table('products')->where('id', $product->id)->update(['abbr' => $abbrname]);
    }


    public function deleted(Product $product)
    {
        //
    }


    public function restored(Product $product)
    {
        //
    }


    public function forceDeleted(Product $product)
    {
        //
    }
}
